<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="jca" uri="http://www.ptc.com/windchill/taglib/components"%>
<%@ include file="/netmarkets/jsp/util/beginPopup.jspf"
%>
<%@ taglib prefix="wrap" uri="http://www.ptc.com/windchill/taglib/wrappers"%>
<%@ taglib prefix="wctags" tagdir="/WEB-INF/tags"%>
<%@ taglib uri="http://www.ptc.com/windchill/taglib/fmt" prefix="fmt"%>

<%@ taglib prefix="mvc" uri="http://www.ptc.com/windchill/taglib/jcaMvc"%>
<%@ taglib uri="http://www.ptc.com/windchill/taglib/mvc" prefix="mvc2"%>
 <%@ taglib prefix="jca" uri="http://www.ptc.com/windchill/taglib/components"%> 
 <%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="wt.fc.Persistable"%>
<%@page import="wt.fc.PersistenceHelper"%>
<%@page import="wt.fc.QueryResult"%>
<%@page import="wt.fc.ReferenceFactory"%>
<%@page import="wt.util.WTException"%>
<%@page import="wt.query.QuerySpec"%>
<%@page import="wt.part.WTPart"%>
<%@page import="com.webridge.wpmtest.util.ContainerUtil"%>
<%
//get Product names
String productStr = ContainerUtil.getAllProducts();



%>

<script>
 PTC.navigation.loadScript('core-ui/1.0/lib/jquery.js')
 PTC.navigation.loadScript('core-ui/1.0/lib/jquery-ui/jquery-ui-custom.js')
Ext.onReady(function(){
	//Ext.MessageBox.alert('info','INFO EXTJS TEST.');
	var storePartInit = new Ext.data.JsonStore({
        fields: ['name','value'],
        data : [] // from states.js
    });

    var prod =  <%=productStr%> ;
	//alert("prod:" + prod);
	var prodJson = eval(prod);
	//alert("prodJson:" + prodJson);
    // simple array store
    var store = new Ext.data.JsonStore({
        fields: ['name','value'],
        //autoLoad: true,
        data : prod// from states.js
    });
    var combo = new Ext.form.ComboBox({
        store: store,
        multi: true,
        id:'pname',
        displayField:"name",
        valueField: "value",
        typeAhead: true,
        mode: 'local',
        //forceSelection: true,
        triggerAction: 'all',
        emptyText:'Select a product...',
        selectOnFocus:true,
        applyTo: 'local-product',
          listeners:{
        	   select:function(combo,record,opts) { 
        	      var productName = record.get("name");
        	      //var pname = Ext.getCmp('pname').getRawValue();
        	      //var oldValue = Ext.getCmp('local-product');
        	      var pname = $("#local-product").val();
        	      alert("pname:" + pname+"productName:" + productName);
        	      $("#local-product").val(pname);
        	      /*alert('pname:' + pname);
        	      //alert(productName);
        	      
        	      //debugger
        	       Ext.Ajax.request({
        	    	  url:'/Windchill/netmarkets/jsp/com/webridge/wpmtest/getTeamJson.jsp?productName='+productName,
        	    	  method:'post',
        	    	  success:
	        	    	  function(response,options){
        	    		  //alert("ajax success.");
        	    		  debugger
	        	    	  var results = Ext.util.JSON.decode(response.responseText);
	        	    	  	var storePart = new Ext.data.JsonStore({
	            		        fields: ['name','value'],
								data:results
	            		    });
	            		  comboPart.clearValue();
	            	      comboPart.bindStore(storePart,false);//绑定store
	        	    	  },
        	    	  failure:
	        	    	  function (){
	        	    	 	 alert("ajax false");
	        	    	  }
        	    	  }); */
        	   },
    'beforequery':function(e){                
        var combo = e.combo;    
        if(!e.forceAll){    
        var input = e.query;
        console.log("input1:" + input);
        input=input.substring(input.lastIndexOf(';')+1,input.length);
        console.log("input2:" + input);
        // 检索的正则  
        var regExp = new RegExp(".*" + input + ".*");  
        // 执行检索  
        combo.store.filterBy(function(record,id){    
        // 得到每个record的项目名称值  
        var text = record.get(combo.displayField); 
        return regExp.test(text);   
        });  
        combo.expand();    
        return false;  
        }  
    }  
          
          
          } 
    });
    
    
    
 //绑定store
  
    
    var comboPart = new Ext.form.ComboBox({
        store: storePartInit,
        displayField:"name",
        valueField: "value",
        typeAhead: true,
        mode: 'local',
        forceSelection: true,
        triggerAction: 'all',
        emptyText:'Select a Team...',
        selectOnFocus:true,
        applyTo: 'team',
    });
	
	
})

function extCount(){
	var x = Ext.getDom("countTest");
	alert(x.value);
	
}


function createPart(){
	//alert("CreatePart");
	var count = document.getElementById("count").value;
	if(count=="")
		{
			alert("Must input Count!");
			return false;
		}
	var type="^[0-9]*[1-9][0-9]*$"; 
	var re = new RegExp(type); 
	if(count.match(re)==null) { 
	　　alert("Must input an Positive Integer. "); 
	　　return false;
	}
	//alert("Part count:"+count);
	var url = "/Windchill/netmarkets/jsp/createParts.jsp?count="+count;
	//alert("URL:"+url);
	window.open(url);
	
	
}


function updatePartName(){
	
	var url = "/Windchill/netmarkets/jsp/updatePartName.jsp";
	//alert("URL:"+url);
	window.open(url);
}




</script>

<font size="2" color="red"><b>WPM Test Item</b></font>
<br/>
<fieldset><legend>1,&nbsp;&nbsp;&nbsp;&nbsp;Create Part Test</legend></fieldset>
<span>Count:</span><input id="count" name="count" value=""/>
<input type="button"  value="Create Parts" onClick="createPart()"/>
<br />
 <br />
 <br />
 <fieldset><legend>2,&nbsp;&nbsp;&nbsp;&nbsp;Batch Update Part Name Test(10mins)</legend></fieldset>
<input type="button"  value="Batch Update Part Name" onClick="updatePartName()"/>
<br />
 <br />
 <br />
  <fieldset><legend>3,&nbsp;&nbsp;&nbsp;&nbsp;PN Test</legend></fieldset>
<input type="button"  value="Promotion Notice Test" onClick="testPN()"/>
<br />
 
 <br />
 <br />
 <br /><br />
 <br />
 <br />
 <br />
 <br />
 <br />
 
 <fieldset><legend>4,&nbsp;&nbsp;&nbsp;&nbsp;ExtJS Test</legend></fieldset>
 
 <span>Count TEST:</span><input id="countTest" name="countTest" value=""/>
 <input type="button"  value="test ext" onClick="extCount()"/>
 
  <fieldset><legend>5,&nbsp;&nbsp;&nbsp;&nbsp;Product-Team Test</legend></fieldset>
 
 <div>
    <span>Products:</span> <input type="text" id="local-product" size="20"/><br/>
    <span>Team:</span> <input type="text" id="team" size="20"/>
</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 <%@include file="/netmarkets/jsp/util/end.jspf"%> 
